package com.guang.springbootthread.test2;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 *类说明：新启线程的方式
 */
public class NewThread {

	/*扩展自Thread类*/
	private static class UseThread extends Thread{
		public UseThread(String name) {
			super(name);
		}

		@Override
		public void run() {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			// do my work;
			System.out.println("I am extendec Thread,当前线程是："+Thread.currentThread().getName());
		}
	}

	
	/*
	* 实现Runnable接口，更加侧重于任务。与线程本身解耦
	* */
	private static class UseRunnable implements Runnable{

		@Override
		public void run() {
			// do my work;
			System.out.println("I am implements Runnable,当前线程是："+Thread.currentThread().getName());

		}
	}
	

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		UseThread useThread = new UseThread("extendsThreadName");
		useThread.start();
		System.out.println("打印线程，当前线程名称是："+Thread.currentThread().getName());
		UseRunnable useRunnable = new UseRunnable();
		new Thread(useRunnable,"implementsThreadName").start();
		System.out.println("main end");
	}
}